package com.Ajava1704.for并发包下的类.conditation;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 作者: LCG
 * 日期: 2020/6/23 22:21
 * 描述:
 */
public class ConditionUtils {

    private Lock lock=new ReentrantLock();

    private Condition conditionA=lock.newCondition();

    private Condition conditionB=lock.newCondition();


    public void waitA(){
        lock.lock();
        try{
            System.out.println("===========Await");
            conditionA.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }

    public void singalA(){

        lock.lock();
        try {
            System.out.println("===========singalA");
            conditionA.signal();
        }finally {
            lock.unlock();
        }

    }


    public void waitB(){
        lock.lock();
        try{
            System.out.println("===========waitB");
            conditionB.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }

    public void singalB(){

        lock.lock();
        try {
            System.out.println("===========singalB");
            conditionB.signal();
        }finally {
            lock.unlock();
        }

    }


}
